var chrom_list = [];
var rgx_datasets = [];
var annotation_dataset = [];
var dudley_dataset = [];
var kruglyak_dataset = [];
var datasets_hash = [];
chrom_list.push({value:'*',label:'*'});
loadAnnotations(function() {
	var i = 0;
	var setarray = dataset_annotations["datalabels"]; 
        for (i = 0; i < setarray.length; i++){
	        var datalabel_hash = setarray[i];
        	rgx_datasets.push({
                                text: datalabel_hash.dslabel,
                                iconCls:'forest',
                                leaf: true,
                                id: datalabel_hash.source + "__" + datalabel_hash.dslabel
                            });

		if (datalabel_hash.source == 'dudley'){
                	dudley_dataset.push({
                                text: datalabel_hash.dslabel,
                                iconCls:'forest',
                                leaf: true,
                                id: datalabel_hash.source + "__" + datalabel_hash.dslabel
                            });
        	}
		if (datalabel_hash.source == 'network'){
                        annotation_dataset.push({
                                text: datalabel_hash.dslabel,
                                iconCls:'forest',
                                leaf: true,
                                id: datalabel_hash.source + "__" + datalabel_hash.dslabel
                            });
                }
		if (datalabel_hash.source == 'kruglyak'){
                	kruglyak_dataset.push({
                                text: datalabel_hash.dslabel,
                                iconCls:'forest',
                                leaf: true,
                                id: datalabel_hash.source + "__" + datalabel_hash.dslabel
                });
                }
	
	}
    });
populateYeastChrom(chrom_list);
var selectedDataset = "";
datasets_hash["annotation_dataset"] = annotation_dataset;
datasets_hash["dudley_dataset"] = dudley_dataset;
datasets_hash["kruglyak_dataset"] = kruglyak_dataset;
var dataset_label = 'KruglyakGenoTranscriptomicsPhenoProteomics';
var scatterplot_window,scatterplot_window_mask;
var order_list = [{value:'Default',label:'Default'},{value:'correlation',label:'Correlation'},{value:'importance',label:'Importance'},{value:'pvalue',label:'PValue'}];
var limit_list = [{value:10,label:'10'},{value:20,label:'20'},{value:50, label:'50'},{value:100, label:'100'},{value:200, label:'200'},
            {value:500, label:'500'}];
var helpWindowReference = null;

function generateFeatureRequest() {
    var f1_type = Ext.getCmp('f1_type_combo').getValue();
    var f1_label;
     switch(f1_type) {
         case('PHENO'):
         f1_label = Ext.getCmp('f1_pheno_label').getValue();
         break;
          default :
           f1_label = Ext.getCmp('f1_label_field').getValue();
    }
     var f2_type = Ext.getCmp('f2_type_combo').getValue();
    var f2_label;
     switch(f2_type) {
         case('PHENO'):
         f2_label = Ext.getCmp('f2_pheno_label').getValue();
         break;
          default :
           f2_label = Ext.getCmp('f2_label_field').getValue();
    }
   var allNetwork = Ext.getCmp('in-network-all').getValue();
   var noneNetwork = Ext.getCmp('in-network-none').getValue();
   //alert('all ' + allNetwork + ' none ' + noneNetwork);
   	
   requestFeatureData(
            f1_type,
            f1_label,
            Ext.getCmp('f1_chr_combo').getValue(),
            Ext.getCmp('f1_chr_start').getValue(),
            Ext.getCmp('f1_chr_stop').getValue(),
            f2_type,
            f2_label,
            Ext.getCmp('f2_chr_combo').getValue(),
            Ext.getCmp('f2_chr_start').getValue(),
            Ext.getCmp('f2_chr_stop').getValue(),
            Ext.getCmp('min_importance').getValue(),
            Ext.getCmp('min_correlation').getValue(),
            Ext.getCmp('order_combo').getValue(),
            Ext.getCmp('limit_combo').getValue(),
	    Ext.getCmp('correlation_fn').getValue(),
	    Ext.getCmp('max_pvalue').getValue(),
	    Ext.getCmp('in-network-none').getValue(),
	    Ext.getCmp('in-network-all').getValue(),
	    Ext.getCmp('in-network-yeastnet').getValue(),
	    Ext.getCmp('in-network-grn').getValue(),
            Ext.getCmp('in-network-genetic').getValue(),
	    Ext.getCmp('in-network-metabolic').getValue(),
            Ext.getCmp('in-network-ppi').getValue(),
            Ext.getCmp('in-network-pri').getValue()	
            );
}

function renderScatterPlot() {
    openSPWindow();
    scatterplot_draw(document.getElementById('scatterplot_panel'));
    scatterplot_window_mask.hide();
}

function openSPWindow() {
    scatterplot_window.show();
    scatterplot_window_mask =  new Ext.LoadMask('scatterplot-window', {msg:"Loading Data..."});
    scatterplot_window_mask.show();
}

function export_svg() {
    var serializer = new XMLSerializer();
    var svg_tags;
    var panel_dom = Ext.get('circle-panel').dom;
    if (panel_dom.firstChild.id == ""){
        svg_tags =serializer.serializeToString(panel_dom.firstChild);
    }
    Ext.getCmp('export-textarea').setRawValue(svg_tags);
}


Ext.onReady(function() {
	    Ext.QuickTips.init();

    var randomforestPanel = new Ext.Panel({
        id:'randomforest-panel',
        name:'randomforest-panel',
        layout : 'border',
        title : 'Yeast Regulome Explorer',
        //iconCls : 'forest',
        tbar: [
                {
                        id:'displayMenu',
                        text:'Highlight',
                        labelStyle: 'font-weight:bold;',
                        menu:[{
                            text:'Top Importance:',
                            menu:[{
                                xtype:'menuitem',
                                 handler: function(){
                                        setImportanceQuantile(.75);
                                        generateFeatureRequest();
                                },
                                id:'hi_25p',
                                text:'25%'
                                },
                                {
                                    xtype:'menuitem',
                                    handler: function(){
                                        setImportanceQuantile(.90);
                                        generateFeatureRequest();
                                    },
                                    id:'hi_10p',
                                    text:'10%'
                                },
                                {
                                    xtype:'menuitem',
                                    handler: function(){
                                        setImportanceQuantile(.95);
                                        generateFeatureRequest();
                                    },
                                    id:'hi_5p',
                                    text:'5%'
                                },
                                {
                                    xtype:'menuitem',
                                    handler: function(){
                                        setImportanceQuantile(.99);
                                        generateFeatureRequest();
                                    },
                                    id:'hi_1p',
                                    text:'1%'
                                }]

                        }]
                    },
			{
                            text:'Dataset',
                            menu:[{
                                xtype:'menuitem',
                                 handler: function(){
					var exptext = "targ_source,targ_label,targ_chr,targ_start,targ_end,pred_source,pred_label,pred_chr,pred_start,pred_end,pvalue,importance,correlation<br>";
					for (var er in currentDataTableData){
						var erObj = currentDataTableData[er]
						if (erObj != undefined && erObj['target_source'] != undefined){
							exptext = exptext + erObj['target_source'] + "," + erObj['target_label'] + "," + erObj['target_chr'] + "," + erObj['target_start'] + "," + erObj['target_stop'] + "," 
							+ erObj["source_source"] + "," + erObj['source_label'] + "," + erObj['source_chr'] + "," + erObj['source_start'] + "," + erObj['source_stop'] +  "," + erObj['pvalue'] + "," + erObj['importance'] + "," + erObj['correlation'] +"<br>";
						}
					}
                                       // document.getElementById("fileframe").src = "/dudley-lims/sequencing/exportastsv?contenttext=" +exptext + "&filename=" + "yeast_associations_regexp.csv";
				var body = Ext.getBody();
               /*			// create a hiddle frame
               		var frame = body.createChild({
                   tag: 'iframe',
                   cls: 'x-hidden',
                   id: 'iframe',
                   name: 'iframe'
               });*/
               //create hidden form with download as action
               var form = body.createChild({
                   tag: 'form',
                   cls: 'x-hidden',
		   method: 'POST',
                   id: 'form',
                   action: '/dudley-lims/sequencing/exportastsv',
                   target: 'fileframe'
               });
               // to set the parameter through a hidden field
               var inputpara = form.createChild({
                   tag: 'input',
                   type: 'hidden',
                   name: 'contenttext', // parameter name
                   value: exptext  // parameter value
               });
               var inputpfilename = form.createChild({
                   tag: 'input',
                   type: 'hidden',
                   name: 'filename', 
                   value: "yeast_associations_regexp.csv"
               });
               // submit the form to initiate the downloading
               form.dom.submit();          
				},
                                id:'csv_exp',
                                text:'Save Results'
                                },
                                {
                                    xtype:'menuitem',
                                    handler: function(){
                               		Ext.Msg.alert("Info", "In progress");   
				  },
                                    id:'svg_exp',
                                    text:'Dataset Info'
                                }
                                ]
                        }
                ],
        defaults: {
            bodyStyle: 'padding:5px',
            animFloat: false,
            floatable: false
        },
        tools: [{
            id: 'help',
            handler: function(event, toolEl, panel){
                openHelpWindow('Random Forest',rfHelpString + "<p>" + viewHelpString);
            }
        }],
        items:[
            {region: 'center', id: 'view-region',
                xtype: 'tabpanel',
                border : false,
                activeTab : 0,
                items: [               {
                    xtype : 'panel', id :'rf-graphical',
                    layout : 'auto', title: 'Graphical',
                    autoScroll : 'true',
                    items: [{
                        xtype: 'panel', id:'circle-parent',
                        layout : 'absolute',
                        height: 900,
                        width:1050,
                        collapsible : true,
                        title : 'Genome-level View',
                        tools: [{
                            id: 'help',
                            handler: function(event, toolEl, panel){
                                openHelpWindow('Genome-level View',genomeLevelHelpString);
                            }}],
                        items : [ {
                            xtype: 'panel', id:'circle-panel',
                            width:800,
                            x:20,
                            y:20
                        },
                            {
                                xtype: 'panel', id:'circle-legend-panel',
                                width:150,
                                border:false,
                                frame : false,
                                x:880,
                                y:20
                            }]
                    }, {
                        xtype: 'panel', id:'linear-parent',
                        layout : 'absolute',
                        height: 800,
                        width:1050,
                        collapsible : true,
                        collapsed : true,
                        title : 'Chromosome-level View',
                        tools: [{
                            id: 'help',
                            handler: function(event, toolEl, panel){
                                openHelpWindow('Chromosome-level View',chromosomeLevelHelpString);
                            }}],
                        items : [ {
                            xtype: 'panel', id:'linear-panel',
                            width:800,
                            x:20,
                            y:20,
                            html: 'For a Chromosome-level view of the data, select a point of focus from the Genome-level View.<p>' +
                                    'Click on:' +
                                    '<ol><li>Chromosome Label</li><li>Tick Label</li>'
                        },
                            {
                                xtype: 'panel', id:'linear-legend-panel',
                                width:150,
                                border:false,
                                frame : false,
                                x:820,
                                y:20
                            }]
                    }]}, {
                    xtype: 'panel',  id:'grid-panel',
                    name : 'grid-panel',
                    title : 'Data Table',
                    autoScroll : 'true',
                    layout : 'auto',
                    height: 650,
                    width:1050,
                    collapsible : false,
                    tools: [{
                        id: 'help',
                        handler: function(event, toolEl, panel){
                            openHelpWindow('Data-level View',dataLevelViewHelpString);
                        }}],
                    items : [
                        {
                            xtype:'grid',
                            id : 'data_grid',
                            name : 'data_grid',
                            height: 650,
                            width:1050,
                            cm : new Ext.grid.ColumnModel({
                                columns: [
                                    { header: "Type", width: 40,  id:'target_source', dataIndex:'target_source',groupName:'Target'},
                                    { header: "Label", width: 120, id: 'target_label',dataIndex:'target_label',groupName:'Target'},
                                    { header: "Chr", width:30 , id:'target_chr', dataIndex:'target_chr',groupName:'Target'},
                                    { header: "Start", width:100, id:'target_start',dataIndex:'target_start',groupName:'Target'},
                                    { header: "Stop", width:100, id:'target_stop',dataIndex:'target_stop',groupName:'Target'},
                                    { header: "Type", width: 40,  id:'source_source', dataIndex:'source_source',groupName:'Source'},
                                    { header: "Label", width: 120, id: 'source_label',dataIndex:'source_label',groupName:'Source'},
                                    { header: "Chr", width:30 , id:'source_chr', dataIndex:'source_chr',groupName:'Source'},
                                    { header: "Start", width:75, id:'source_start',dataIndex:'source_start',groupName:'Source'},
                                    { header: "Stop", width:75, id:'source_stop',dataIndex:'source_stop',groupName:'Source'},
                                    { header: "Importance", width:50, id:'pvalue',dataIndex:'pvalue'},
				    { header: "Importance", width:50, id:'importance',dataIndex:'importance'},
                                    { header: "Correlation", width:50, id:'correlation',dataIndex:'correlation'}
                                ],
                                defaults: {
                                    sortable: true,
                                    width: 100
                                }
                            }),
                            store : new Ext.data.JsonStore({
                                autoLoad:false,
                                storeId:'data_grid_store',
                                fields : ['target_source','target_label','target_chr','target_start','target_stop',
                                    'source_source','source_label','source_chr','source_start','source_stop','pvalue','importance','correlation']
                            })
                        }]
                }]
            },
            {region: 'east',
                collapsible: true,
                floatable: true,
                autoHide:false,
                split: true,
                width: 270,
                title: 'Filter',

                layout: {
                    type: 'accordion'
                },
                tools: [{
                    id: 'help',
                    handler: function(event, toolEl, panel){
                        openHelpWindow('Tools',toolsHelpString);
                    }}],
                items: [{
                    xtype: 'panel', id:'filterpanel_id',
                    title : dataset_label,	
                    autoScroll : true,
                    height : 250,
                    tools: [{
                        id: 'help',
                        handler: function(event, toolEl, panel){
                            openHelpWindow('Filtering',filteringHelpString);
                        }}],
                    items :[
                        { xtype:'form',
                            id :'filter_panel',
                            name :'filter_panel',
                            bodyStyle:'padding:5px 5px 5px 5px',
                            defaults:{anchor:'100%'},
                            border : false,
                            labelAlign : 'right',
                            labelWidth: 70,
                            labelSeparator : '',
                            defaultType:'textfield',
                            monitorValid : true,
			    keys: [
                			{
                    			key: [Ext.EventObject.ENTER],
                    			fn: function() {
                        		Ext.ComponentMgr.get('rgx_search_buttonid').fireEvent('click');
                    			}}
            			  ],            
                            buttons : [
                                {
                                    text: 'Search',
                                    formBind : true,
				    id: 'rgx_search_buttonid',	
                                    listeners : {
                                        click : function(button,e) {
					    /*if (Ext.getCmp('in-network-radio-gene').getValue()){
					    	//selectDataset(selectedDataset + "_grnw")
						var currentDataset = {};
						currentDataset['network_uri'] = '/mv_' + selectedDatalabel + '_grnw_feature_associations/query',
			                        currentDataset['patient_uri'] = '/v_' + selectedDatalabel + '_strains/query',
                        			currentDataset['feature_data_uri'] = '/v_' + selectedDatalabel + '_strain_values/query';
                        			selectDataset(currentDataset);
					    }*/
					    //if (Ext.getCmp('in-network-radio-all').getValue()){						
                                            //    selectDataset(selectedDataset);
                                            //}			
                                            generateFeatureRequest();
                                        }
                                    }
                                },
                                { text: 'Reset',
                                    listeners : {
                                        click : function(button,e) {
                                            Ext.getCmp('f1_type_combo').reset(),
                                                    Ext.getCmp('f1_label_field').reset(),
                                                    Ext.getCmp('f1_chr_combo').reset(),
                                                    Ext.getCmp('f1_chr_start').reset(),
                                                    Ext.getCmp('f1_chr_stop').reset(),
                                                    Ext.getCmp('f2_type_combo').reset(),
                                                    Ext.getCmp('f2_label_field').reset(),
                                                    Ext.getCmp('f2_chr_combo').reset(),
                                                    Ext.getCmp('f2_chr_start').reset(),
                                                    Ext.getCmp('f2_chr_stop').reset(),
                                                    Ext.getCmp('min_importance').reset(),
                                                    Ext.getCmp('min_correlation').reset(),
						    Ext.getCmp('min_correlation2').reset(),
                                                    Ext.getCmp('order_combo').reset(),
                                                    Ext.getCmp('limit_combo').reset(),
						    Ext.getCmp('in-network-radio-all').reset()
						    //Ext.getCmp('highlight_network_combo').reset()
                                        }
                                    }
                                }
                            ],
                            items : [
                                {  xtype:'fieldset',
                                    title:'Target',
                                    collapsible: true,
                                    defaults:{anchor:'100%'},
                                    labelWidth: 70,
                                    labelSeparator : '',
                                    defaultType:'textfield',
                                    autoHeight:true,
                                    items:[
                                        {
                                            xtype:'combo',
                                            name:'f1_type_combo',
                                            id:'f1_type_combo',
                                            mode:'local',
                                            allowBlank : true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                data: [
                                                    {value: '*',label:'All'},
                                                    {value: 'GEXP',label:'Gene Expression'},
                                                    {value: 'PROT',label:'Proteomic'},
                                                    {value: 'GENO',label:'Genotype'},
                                                    {value: 'PHENO',label:'Phenotype'},
						    {value: 'GRNW',label:'Gene Regulatory Network'}
                                                ],
                                                storeId:'f1_type_combo_store'
                                            }),
                                            fieldLabel:'Type',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 0,
                                            typeAhead : true,
                                            selectOnFocus:true,
                                            triggerAction : 'all',
                                            forceSelection : true,
                                            emptyText : 'Select a Type...',
                                            value : '*',
					    listeners : {
                                                 select : function(field,record, index) {
                                                                    switch(record.id)  {
                                                        case('PHENO'):
                                                                  var label_cmp = Ext.getCmp('f1_label_field'),
                                                                  pheno_cmp = Ext.getCmp('f1_pheno_label');
                                                        	  label_cmp.setVisible(false);
                                                        	  pheno_cmp.setVisible(true);
                                                                break;
                                                        default:
                                                        	var label_cmp = Ext.getCmp('f1_label_field'),
                                                                pheno_cmp = Ext.getCmp('f1_pheno_label');
                                                        	label_cmp.setVisible(true);
                                                        	pheno_cmp.setVisible(false);
                                                    }
                                                }
                                            }
                                        }, {
                                            name:'f1_label_field',
                                            id:'f1_label_field',
                                            emptyText : 'Input Label...',
                                            tabIndex: 1,
                                            selectOnFocus:true,
                                            fieldLabel:'Label'
                                        },
					{
                                            name:'f1_pheno_label',
                                            mode:'local',
                                            id:'f1_pheno_label',
                                            xtype:'combo',
                                            allowBlank : false,
                                            hidden:true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : false,
                                                data: phenoList,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                storeId:'f1_pheno_list_store'
                                            }),
                                            listWidth:200,
                                            fieldLabel:'Phenotype',
                                            selectOnFocus:true,
                                            forceSelection : true,
                                            triggerAction : 'all',
                                            valueField:'value',
                                            displayField:'label',
                                            emptyText:'Phenotype Feature...',
                                            value:'*'
                                        },
                                        { xtype:'combo', name:'f1_chr_combo',id:'f1_chr_combo',
                                            mode:'local',
                                            allowBlank : false,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                data: chrom_list,
                                                storeId:'f1_chr_combo_store'
                                            }),
                                            fieldLabel:'Chromosome',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 2,
                                            selectOnFocus:true,
                                            forceSelection : true,
                                            triggerAction : 'all',
                                            emptyText : 'Select Chr...',
                                            value : '*'
                                        },{xtype : 'numberfield',
                                            id:'f1_chr_start',
                                            name :'f1_chr_start',
                                            allowNegative: false,
                                            decimalPrecision : 0,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            maxValue: 99999999,
                                            minValue:1,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            allowDecimals : false,
                                            fieldLabel : 'Start >=',
                                            value : ''
                                        },{xtype : 'numberfield',
                                            id:'f1_chr_stop',
                                            name :'f1_chr_stop',
                                            allowNegative: false,
                                            decimalPrecision : 0,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            maxValue: 250999999,
                                            minValue:1,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            allowDecimals : false,
                                            fieldLabel : 'Stop <=',
                                            value : ''
                                        }

                                    ]},
                                {  xtype:'fieldset',
                                    title:'Predictor',
                                    collapsible: true,
                                    defaults:{anchor:'100%'},
                                    labelWidth: 70,
                                    labelSeparator : '',
                                    defaultType:'textfield',
                                    autoHeight:true,
                                    items:[
                                        {
                                            xtype:'combo',
                                            name:'f2_type_combo',
                                            id:'f2_type_combo',
                                            mode:'local',
                                            allowBlank : true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
						data: [
                                                    {value: '*',label:'All'},
                                                    {value: 'GEXP',label:'Gene Expression'},
                                                    {value: 'PROT',label:'Proteomic'},
                                                    {value: 'GENO',label:'Genotype'},
                                                    {value: 'PHENO',label:'Phenotype'}
                                                ],
                                                storeId:'f2_type_combo_store'
                                            }),
                                            fieldLabel:'Type',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 0,
                                            typeAhead : true,
                                            selectOnFocus:true,
                                            triggerAction : 'all',
                                            forceSelection : true,
                                            emptyText : 'Select a Type...',
                                            value : '*',
					    listeners : {
                                                 select : function(field,record, index) {
                                                                    switch(record.id)  {
                                                        case('PHENO'):
                                                                  var label_cmp = Ext.getCmp('f2_label_field'),
                                                                  pheno_cmp = Ext.getCmp('f2_pheno_label');
                                                                  label_cmp.setVisible(false);
                                                                  pheno_cmp.setVisible(true);
                                                                break;
                                                        default:
                                                                var label_cmp = Ext.getCmp('f2_label_field'),
                                                                pheno_cmp = Ext.getCmp('f2_pheno_label');
                                                                label_cmp.setVisible(true);
                                                                pheno_cmp.setVisible(false);
                                                    }
                                                }
                                            }	
                                        }, {
                                            name:'f2_label_field',
                                            id:'f2_label_field',
                                            emptyText : 'Input Label...',
                                            tabIndex: 1,
                                            selectOnFocus:true,
                                            fieldLabel:'Label'
                                        },
					{
                                            name:'f2_pheno_label',
                                            mode:'local',
                                            id:'f2_pheno_label',
                                            xtype:'combo',
                                            allowBlank : false,
                                            hidden:true,
                                            store: new Ext.data.JsonStore({autoLoad : false,
                                                data: phenoList,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                storeId:'f2_pheno_list_store'
                                            }),
                                            listWidth:200,
                                            fieldLabel:'Phenotype',
                                            selectOnFocus:true,
                                            forceSelection : true,
                                            triggerAction : 'all',
                                            valueField:'value',
                                            displayField:'label',
                                            emptyText:'Phenotype Feature...',
                                            value:'*'
                                        },
                                        { xtype:'combo', name:'f2_chr_combo',id:'f2_chr_combo',
                                            mode:'local',
                                            allowBlank : true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                data: chrom_list,
                                                storeId:'f2_chr_combo_store'
                                            }),
                                            fieldLabel:'Chromosome',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 2,
                                            selectOnFocus:true,
                                            forceSelection : true,
                                            triggerAction : 'all',
                                            emptyText : 'Select Chr...',
                                            value : '*'
                                        },{xtype : 'numberfield',
                                            id:'f2_chr_start',
                                            name :'f2_chr_start',
                                            allowNegative: false,
                                            decimalPrecision : 0,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            maxValue: 99999999,
                                            minValue:1,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            allowDecimals : false,
                                            fieldLabel : 'Start >=',
                                            value : ''
                                        },{xtype : 'numberfield',
                                            id:'f2_chr_stop',
                                            name :'f2_chr_stop',
                                            allowNegative: false,
                                            decimalPrecision : 0,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            maxValue: 250999999,
                                            minValue:1,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            allowDecimals : false,
                                            fieldLabel : 'Stop <=',
                                            value : ''
                                        }
                                    ]},
                                {  xtype:'fieldset',
                                    defaults:{anchor:'100%'},
                                    labelWidth : 90,
                                    labelSeparator : '',
                                    title:'Associated Network',
                                    collapsible: true,
                                    autoHeight:true,
                                    items:[
                                        {xtype : 'numberfield',
                                            id:'min_importance',
                                            name :'min_importance',
                                            decimalPrecision : 4,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            minValue:0,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            fieldLabel : 'Importance >=',
                                            value : 0.001,
					    listeners: {
                                                render: function(c) {
                                                        Ext.QuickTips.register({
                                                        target: c,
                                                        title: '',
                                                        text: 'Filter by Importance score, must be numeric and importance > 0'
                                                });
                                                }
                                        }},
					/*{
                                            xtype:'combo',
                                            name:'highlight_network_combo',
                                            id:'highlight_network_combo',
                                            mode:'local',
                                            allowBlank : true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                data: [
                                                    {value: '*',label:'None'},
                                                    {value: '.75',label:'25%'},
                                                    {value: '.9',label:'10%'},
                                                    {value: '.95',label:'5%'},
                                                    {value: '.99',label:'1%'}
                                                ],
                                                storeId:'highlight_combo_store'
                                            }),
                                            fieldLabel:'Top Importance Highlight',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 0,
                                            typeAhead : true,
                                            selectOnFocus:true,
                                            triggerAction : 'all',
                                            forceSelection : true,
                                            emptyText : 'Highlight...',
                                            value : '.75',
                                            listeners : {
                                                 select : function(field,record, index) {
								setImportanceQuantile(record.id);
                                                }
                                            }  
                                        },*/
					{xtype : 'numberfield',
                                            id:'max_pvalue',
                                            name :'max_pvalue',
                                            allowNegative: false,
                                            decimalPrecision : 4,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            maxValue:1,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            fieldLabel : 'PValue <=',
                                            value : 0.1,
                                            listeners: {
                                                render: function(c) {
                                                        Ext.QuickTips.register({
                                                        target: c,
                                                        title: '',
                                                        text: 'Filter by PValue significance, must be numeric and 1 >= pvalue >= 0'
                                                });
                                                }
                                        }},     
					{
                        xtype : 'compositefield',
                        anchor: '-20',
                        msgTarget: 'side',
                        fieldLabel: 'Correlation',
                        items : [
                            {
                                width:          50,
                                id:'correlation_fn',
                                name :'correlation_fn',
                                xtype:          'combo',
                                mode:           'local',
                                value:          'Abs',
                                triggerAction:  'all',
                                forceSelection: true,
                                editable:       false,
                                fieldLabel:     'Fn',
                                displayField:   'name',
                                valueField:     'value',
                                store:          new Ext.data.JsonStore({
                                    fields : ['name', 'value'],
                                    data   : [
                                        {name : '>=',   value: '>='},
                                        {name : '<=',  value: '<='},
                                        {name : 'Abs', value: 'Abs'},
					{name : 'Btw', value: 'Btw'}
                                    ]
                                }),
                                 listeners: {
                                            render: function(c) {
                                                Ext.QuickTips.register({
                                                target: c,
                                                title: '',
                                                text: 'Implies if corr value (x)=.5, Abs is a filtering of (x >= .5 OR x <= -.5) <br>Btw is a filtering of (x >= -.5 AND x <= .5)'
                                            });
                                                }
                                          }

                            },
                            {xtype : 'numberfield',
                                            id:'min_correlation',
                                            name :'min_correlation',
                                            decimalPrecision : 2,
                                            emptyText : 'Input value...',
                                            invalidText:'This value is not valid.',
                                            minValue:0,
					    width: 40,
                                            tabIndex : 1,
                                            validateOnBlur : true,
                                            fieldLabel : 'Range(Corr)',
                                            value : 0.1,
                                            listeners: {
                                            render: function(c) {
                                                Ext.QuickTips.register({
                                                target: c,
                                                title: '',
                                                text: 'Numeric field with 2 decimal precision'
                                            });
                                                }
                                          }
                          }
			]
                    },
	{xtype:'checkbox',
                fieldLabel: 'Networks',
                labelSeparator: '',
                boxLabel: 'YEASTNET',
                id: 'in-network-yeastnet',
                listeners: {      
                        render: function(c) { 
                                     Ext.QuickTips.register({
                                      target: c, title: '', text: 'http://www.yeastnet.org/        Co-citation,Co-expression,Gene-neighbourhood,Genetic interaction,PPI,co-inheritance,functional linkage'
                                });
                }
            }},
          {xtype:'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'Gene Regulatory',
                id: 'in-network-grn',
                listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({
                                      target: c, title: '', text: 'YEASTRACT(http://www.yeastract.com) Gene Regulatory interaction'
                                });
                }
            }},
           {xtype:'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'Genetic',
                id: 'in-network-genetic',
                listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({
                                      target: c, title: '', text: 'Costanzo (http://www.ncbi.nlm.nih.gov/pubmed/20093466) Gene Regulatory interaction'                                });
                }
            }},
		{xtype:'checkbox',
                fieldLabel: '', 
                labelSeparator: '',
                boxLabel: 'Metabolic',
                id: 'in-network-metabolic',
                listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({
                                      target: c, title: '', text: 'CONSENSUS (http://www.comp-sys-bio.org/yeastnet/) enzyme-enzyme network'});
                }
            }},
	   {xtype:'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'ProtProt',
                id: 'in-network-ppi',
		listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({
                                      target: c,
                                      title: '',
                                      text: 'Biogrid(http://thebiogrid.org) protein rna interaction'
                                });
                }
            }},
            {xtype:'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'ProtRNA',
                id: 'in-network-pri',
                listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({                                      target: c,
                                      title: '',
                                      text: 'Biogrid(http://thebiogrid.org) protein rna interaction'
                                });
                }
            }},
	    {xtype:'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'All',
                id: 'in-network-all',
		handler: function(){
                        if (Ext.getCmp("in-network-all").getValue()){
                                        Ext.getCmp("in-network-none").setValue(false);
			}
		},
                listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({
                                      target: c,
                                      title: '',
                                      text: 'Includes all the networks described above, sources are Biogrid, Costanzo, Complexome, Interactome, Yeastract, YEASTNET'
                                });
                }
            }},
	    {xtype:'checkbox',
                fieldLabel: '',
                labelSeparator: '',
                boxLabel: 'None',
                id: 'in-network-none',
		handler: function() {
			if (Ext.getCmp("in-network-none").getValue()){
                                        Ext.getCmp("in-network-all").setValue(false);
                                        Ext.getCmp("in-network-yeastnet").setValue(false);
					Ext.getCmp("in-network-grn").setValue(false);
					Ext.getCmp("in-network-genetic").setValue(false);
					Ext.getCmp("in-network-metabolic").setValue(false);
					Ext.getCmp("in-network-ppi").setValue(false);
					Ext.getCmp("in-network-pri").setValue(false);
                                }
		},
                listeners: {
                              render: function(c) {
                                      Ext.QuickTips.register({
                                      target: c,
                                      title: '',
                                      text: 'Checked means that none of the networks belong to any known Genetic, GRN, Metabolic, PPI and PRI'
                                })}
                }
            },
	{ xtype:'combo', name:'order_combo',id:'order_combo',
                                            mode:'local',
                                            allowBlank : true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                data: order_list,
                                                storeId:'order_combo_store'
                                            }),
                                            fieldLabel:'Order By',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 2,
                                            typeAhead : true,
                                            selectOnFocus:true,
                                            triggerAction : 'all',
                                            value : 'Default'
                                        },
                                        { xtype:'combo', name:'limit_combo',id:'limit_combo',
                                            mode:'local',
                                            allowBlank : true,
                                            store: new Ext.data.JsonStore({
                                                autoLoad : true,
                                                fields : ['value','label'],
                                                idProperty:'value',
                                                data: limit_list,
                                                storeId:'limit_combo_store'
                                            }),
                                            fieldLabel:'Max Results',
                                            valueField:'value',
                                            displayField:'label',
                                            tabIndex : 2,
                                            typeAhead : true,
                                            selectOnFocus:true,
                                            triggerAction : 'all',
                                            value : 200
                                        }
                                    ]
                                }
                            ]
                        }]},
		]
            }]
    });

    var parallelcoordinatesPanel = new Ext.Panel({
        id :'pc-panel',
        name :'pc-panel',
        title : 'Parallel Coordinates',
        layout : 'border',
        tools: [{
            id: 'help',
            handler: function(event, toolEl, panel){
                openHelpWindow('Parallel Coordinates',parCoordHelpString);
            }
        }],
        items:[{
            region:'center',
            xtype:'tabpanel',
            id:'pc-tabpanel',
            name:'pc-tabpanel',
            border : false,
            activeTab : 0,
            items:[{
                xtype:'panel',
                id:'pc-items',
                iconCls:'parallel_coordinates',
                    autoScroll : true,
                    title : 'Graphic',
                    layout : 'auto',
                items:[{
                    id:'pc_text',
                    padding	:'5',
                    border :false,
                    html :'<p>The parallel coordinates plot below shows the three different cancer ' +
                            'types with their associated structural variation counts for each gene.  A range of items can be ' +
                            'selected by clicking and dragging the mouse on any given column.  In this way, genes that display a ' +
                            'trend across cancer types can be selected and further explored.'
                },{
                    xtype:'panel',
                    id:'pc_draw',
                    name:'pc_draw'
                },{xtype:'panel',
                                       border : false,
                                       buttonAlign : 'center',
                               buttons:[
                               {	xtype :	'button',
                                       x:0,
                                       y:0,
                                   text:'Add Filtered Set',
                                   listeners : {
                                       click : function() {
                                           var set = paco_obj.getFiltered();
                                           var record_set = set.map(function(json){return new (Ext.StoreMgr.get('pc_selection_store')).recordType(json,json.gene);})
                                           appendToPCSelectionGrid(record_set);
                                       }
                                   }
                               },
                               {   xtype:'button',
                                   x:30,
                                   y:0,
                                   text:'Add Selection',
                                   listeners : {
                                       click : function() {
                                           var json = paco_obj.getSelected();
                                           if (json ==null) { return;}
                                          var record = new (Ext.StoreMgr.get('pc_selection_store')).recordType(json,json.gene);
                                           appendToPCSelectionGrid(record);
                                       }
                                   }
                               }
                           ]}]

            },{
                xtype:'grid',
                id:'pc_table',
                iconCls : 'table',
                draggable : true,
                ddGroup : 'pc_drag_group',
                enableDragDrop   : true,
                stripeRows       : true,
                name:'pc_table',
                title : 'Data Table',
                cm: new Ext.grid.ColumnModel({
                    defaults : {
                        width : 120,
                        sortable : true
                    },
                    columns : [
                        {id : 'gene', header:'Gene', dataIndex:'gene'},
                        {id : 'COAD',header: 'COAD', dataIndex: 'COAD'},
                        {id : 'GBM',header: 'GBM', dataIndex: 'GBM'},
                        {id : 'OV',header: 'OV', dataIndex: 'OV'}
                    ]
                }),
                store: new Ext.data.JsonStore({
                    autoLoad: false,
                    storeId:'pc_table_store',
                    fields: ['gene', 'COAD', 'GBM', 'OV'],
                    sortInfo : {
                        field : 'gene',
                        direction : 'ASC'
                    },
                    idProperty : 'gene'
                })
            }]
        },{
            region: 'east',
            layout : 'anchor',
            width:300,
            split: true,
            id:'pc_selection_panel',
            title:'Selections',
            collapsible : true,
            minimizable : true,
            collapsed : false,

            items : [{
                id:'pc_selection_grid',
                name:'pc_selection_grid',
                xtype:'grid',
                margins: '0 5 5 0',
                height : 400,
                border:true,
                autoScroll: true,
                ddGroup : 'pc_drag_group',
                pruneModifiedRecords : true,
                stripeRows       : true,
                cm: new Ext.grid.ColumnModel({
                    defaults : {
                        width : 60,
                        sortable : true
                    },
                    columns : [
                        {id : 'gene', header:'Gene', dataIndex:'gene', width:90},
                        {id : 'COAD',header: 'COAD', dataIndex: 'COAD'},
                        {id : 'GBM',header: 'GBM', dataIndex: 'GBM'},
                        {id : 'OV',header: 'OV', dataIndex: 'OV'}
                    ]
                }),
                store: new Ext.data.JsonStore({
                    autoLoad: false,
                    storeId:'pc_selection_store',
                    fields: ['gene', 'COAD', 'GBM', 'OV'],
                    sortInfo : {
                        field : 'gene',
                        direction : 'ASC'
                    },
                    idProperty : 'gene'
                }),
                buttons: [{
                xtype:'button',
                        text:'Remove Selection',
                        listeners : {
                            click : function(e) {
                                var grid = Ext.getCmp('pc_selection_grid');
                                var sels = grid.getSelectionModel().getSelections();
                                if (sels.length > 0) {
                                    grid.getStore().remove(sels);
                                }
                            }
                        }
                },{
                xtype:'button',
                        text:'Remove All',
                        listeners : {
                            click : function(e) {
                                var grid = Ext.getCmp('pc_selection_grid');
                                    grid.getStore().removeAll();
                            }
                        }
                }],
                listeners : {
                    render : setupSelectionDropTarget
                }
           }]
        }],
        listeners : {
            render : function() {
		//loadAnnotations(renderCancerPaCo);
		}
        }
    });

    function setupSelectionDropTarget() {
        var pcSelectionDropTarget = new Ext.dd.DropTarget(Ext.getCmp('pc_selection_grid').getView().scroller.dom, {
            ddGroup     : 'pc_drag_group',
            notifyDrop : function(ddSource, e, data){
                var records =  ddSource.dragData.selections;
                appendToPCSelectionGrid(records);
                return true;
            }
        });
    }
    function appendToPCSelectionGrid(records) {
        var grid = Ext.getCmp('pc_selection_grid');

        Ext.each(records, grid.store.remove, grid.store);
        try{
        grid.store.add(records);
        grid.store.sort('gene', 'ASC');
        }
        catch(e) {
            console.log(e);
        }
        return true;
    }

    new Ext.Viewport({
        layout: {
            type: 'border',
            padding: 5
        },
        defaults: {
            split: true
        },
        items: [
            {
            region: 'north', id:'toolbar-region',
            collapsible: false,
            border : false,
            //title: 'Systems Genetics Regulome Explorer',
            split: false,
            //height: 27,
            layout : 'fit'
	    /*,
	    tbar: [
		{
                        id:'displayMenu',
                        text:'Highlight',
                        labelStyle: 'font-weight:bold;',
                        menu:[{
                            text:'Top Importance:',
                            menu:[{
                                xtype:'menuitem',
                                 handler: function(){
					setImportanceQuantile(.75);
					generateFeatureRequest();
				},
                                id:'hi_25p',
                                text:'25%'
                                },
                                {
                                    xtype:'menuitem',
                                    handler: function(){
					setImportanceQuantile(.90);
                                        generateFeatureRequest();	
				    },
                                    id:'hi_10p',
                                    text:'10%'
                                },
				{
                                    xtype:'menuitem',
                                    handler: function(){
                                        setImportanceQuantile(.95);
                                        generateFeatureRequest();
                                    },
                                    id:'hi_5p',
                                    text:'5%'
                                },
				{
                                    xtype:'menuitem',
                                    handler: function(){
                                        setImportanceQuantile(.99);
                                        generateFeatureRequest();
                                    },
                                    id:'hi_1p',
                                    text:'1%'
                                }]

                        }]
                    }
		]*/
	},
            {region: 'west',
            id:'nav-region',
            collapsible: true,
            expanded: true,
            width: 200,
            layout: {
                type: 'vbox',
                padding: '5,5,5,5',
                align: 'stretch'
            },
            defaults : {
                padding : '0, 0, 5, 0'
            },
            items : [{xtype:'treepanel',
                title: 'Navigation',
                iconCls: 'navigation',
                rootVisible: false,
                lines: false,
                singleExpand: true,
                tools: [{
                    id: 'help',
                    handler: function(event, toolEl, panel){
                        openHelpWindow('Navigation',navHelpString);
                    }
                }],
                useArrows: true,
                height : 380,
                padding: '5',
                autoScroll: true,
                loader: new Ext.tree.TreeLoader(),
                root: new Ext.tree.AsyncTreeNode({
                    expanded: true,
                    children: [{
                        text: 'Home Page',
                        iconCls: 'home',
                        leaf: true,
                        id: 'homepage'
                    },
		    {text: 'Datasets',
			leaf: false,
			iconCls : 'folder',
			id: 'datasetFolder',
			expanded: true,
			children: [ 
				{text: 'Kruglyak',
                        leaf: false,
                        iconCls : 'feature_associations',
                        id: 'kruglyak_root',
			expanded: false,
                        children: datasets_hash["kruglyak_dataset"]
			},
			{text: 'Dudley',
                        leaf: false,
                        iconCls : 'feature_associations',
                        id: 'dudley_root',
                        expanded: false,
                        children: datasets_hash["dudley_dataset"] 
			},
			{text: 'Networks',
                        leaf: false,
                        iconCls : 'feature_associations',
                        id: 'networks_root',
                        expanded: false,
                        children: datasets_hash["annotation_dataset"]
			}/*,
			{text: 'Datasets',
                        leaf: false,
                        iconCls : 'feature_associations',
                        id: 'dataset_root',
                        //expanded: true,
                        children: rgx_datasets
                        }*/
                    ]}
		]
                }),
                listeners : {
                    click : function(selected_node) {
			if (selected_node.id == "dudley_root" || selected_node.id == "kruglyak_root" || selected_node.id == "networks_root"){
				selected_node.expand();
				return;
			}
			if (selected_node.parentNode.id == "networks_root"){
				selected_node.expand();
				Ext.getCmp('f1_type_combo').setValue("*");
                                Ext.getCmp('min_importance').setValue("");
                                Ext.getCmp('max_pvalue').setValue("");
                                Ext.getCmp('min_correlation').setValue("");	
			}else{
				resetFormPanel();
			}
			selectedDatalabel = (selected_node.id).split("__")[1];
			var currentDataset = {};
			currentDataset['network_uri'] = '/mv_' + selectedDatalabel + '_feature_associations/query',
                        currentDataset['patient_uri'] = '/v_' + selectedDatalabel + '_strains/query',
                        currentDataset['feature_data_uri'] = '/v_' + selectedDatalabel + '_strain_values/query';
			selectDataset(currentDataset);
			Ext.getCmp("filterpanel_id").setTitle(selected_node.id);
			Ext.getCmp('nav-region').collapse();
			Ext.getCmp('center-panel').layout.setActiveItem('randomforest-panel');
                        switch(selected_node.id){
			    case('dudley__ycr6'):
				Ext.getCmp('f1_type_combo').setValue("GENO");
				Ext.getCmp('f1_pheno_label').setValue("RAP");
                                //if (Ext.get('circle-panel').dom.firstChild.id != ""){
                                generateFeatureRequest();
                                //}
                                break;
			    case('network__gene_regulatory'):
                                //Ext.getCmp("filterpanel_id").setTitle("Gene Regulatory Networks");
                                //Ext.getCmp('center-panel').layout.setActiveItem('randomforest-panel');
                                //Ext.getCmp('nav-region').collapse();
                                Ext.getCmp('f1_type_combo').setValue("*");
                                Ext.getCmp('min_importance').setValue("");      
                                Ext.getCmp('max_pvalue').setValue("");
                                Ext.getCmp('min_correlation').setValue("");
                                generateFeatureRequest();
                                break;	
                            case('pc_compare'):
                                Ext.getCmp('center-panel').layout.setActiveItem('pc-panel');
                                break;
                            case('homepage'):
                                Ext.getCmp('center-panel').layout.setActiveItem('homepage-panel');
                                break;
                            case('ov_sv'):
                            case('gbm_sv'):
                                openFastbreakTab();
                            /*default:
				Ext.getCmp("filterpanel_id").setTitle(selected_node.id);
                                Ext.getCmp('center-panel').layout.setActiveItem('randomforest-panel');
                                Ext.getCmp('nav-region').collapse();
                                //selectDataset(selected_node.id);
                                //if (Ext.get('circle-panel').dom.firstChild.id != ""){
                                //    generateFeatureRequest();
                                //}
                                break;
				*/
                        }
			generateFeatureRequest();
                    }
                }
            }]
            },
            { region:'center',
            id:'center-panel', name:'center-panel',
            layout:'card',
            border:false,
            closable:false,
            activeItem:0,
            height: 800,
            margins: '0 5 5 0',
            items:[{
                id:'homepage-panel',
                iconCls:'home',
                layout: 'fit',
                autoScroll : true,
                autoLoad : {
                    url : 'home_tab.html'
                },
                title: 'Home'
            }
                ,parallelcoordinatesPanel
                ,randomforestPanel
            ]
        }
        ],
        renderTo:Ext.getBody()
    });
    scatterplot_window =
            new Ext.Window({
                id          : 'scatterplot-window',
                renderTo    : 'view-region',
                modal       : false,
                closeAction : 'hide',
                layout      : 'anchor',
                width       : 500,
                height      : 400,
                title       : "Scatterplot",
                closable    : true,
                layoutConfig : {
                    animate : true
                },
                maximizable : false,
                items : [{
                    xtype:'panel',
                    id:'scatterplot_panel',
                    name:'scatterplot_panel',
                    margins: '3 0 3 3',
                    height : 400,
                    width : 500,
                    frame:true
                }]
            });
    scatterplot_window.hide();
   /* 
    loadAnnotations(function() {
	return;                        
    });
    */
});

function requestFeatureData() {
    arg_obj = {f1_type:arguments[0],f1_label:arguments[1], f1_chr:arguments[2], f1_start:arguments[3],f1_stop:arguments[4],
        f2_type:arguments[5],f2_label:arguments[6], f2_chr:arguments[7], f2_start:arguments[8],f2_stop:arguments[9],
        importance:arguments[10],correlation:arguments[11],order:arguments[12],limit:arguments[13],correlation_fn:arguments[14],pvalue:arguments[15],
        nonenetwork:arguments[16],allnetwork:arguments[17],yeastnet:arguments[18],grn:arguments[19],genetic:arguments[20],metabolic:arguments[21],
	ppi:arguments[22],pri:arguments[23]};
    loadFilteredData(arg_obj);
}

function openHelpWindow(subject,text) {
    if (helpWindowReference == null || helpWindowReference.closed) {
        helpWindowReference = window.open('','help-popup','width=400,height=300,resizable=1,scrollbars=1,status=0,'+
        'titlebar=0,toolbar=0,location=0,directories=0,menubar=0,copyhistory=0');
    }
        helpWindowReference.document.title='Help - ' + subject;
        helpWindowReference.document.body.innerHTML = '<b>' + subject +'</b><p><div style=width:350>' + text + '</div>';
        helpWindowReference.focus();
}
function resetFormPanel() {
    	    Ext.getCmp('f1_type_combo').reset(),
            Ext.getCmp('f1_label_field').reset(),
            Ext.getCmp('f1_chr_combo').reset(),
            //Ext.getCmp('f1_clin_label').reset(),
            Ext.getCmp('f1_chr_start').reset(),
            Ext.getCmp('f1_chr_stop').reset(),
            Ext.getCmp('f2_type_combo').reset(),
            Ext.getCmp('f2_label_field').reset(),
            Ext.getCmp('f2_chr_combo').reset(),
            //Ext.getCmp('f2_clin_label').reset(),
            Ext.getCmp('f2_chr_start').reset(),
            Ext.getCmp('f2_chr_stop').reset(),
            Ext.getCmp('min_importance').reset(),
            Ext.getCmp('min_correlation').reset(),
            Ext.getCmp('order_combo').reset(),
            Ext.getCmp('limit_combo').reset(),
	    Ext.getCmp('max_pvalue').reset(),
	    Ext.getCmp('in-network-all').reset()	
}

var navHelpString = 'The Navigation Panel provides a way to navigate the site.  <br/>' +
        'Clicking on an arrow will expand an item.  Selecting an item without an arrow will display the corresponding view in the main panel.',
 cancerComparatorHelpString = 'The Cancer Comparator Panel provides a way to compare features across cancers.  ' +
'<p>The Parallel Coordinates view displays each cancer as a separate column.  Points on the cancer columns represent the ' +
         'number of structural variations found in a given gene for that cancer type.<p>' +
'Selection of ranges on each of the three cancer columns can be done by clicking and dragging the mouse on a given ' +
'column.  In this way, trends of structural variations across cancer types can be viewed.   Additionally, items can be ' +
'selected and transferred to a gene list for further investigation. <p>' +
'The underlying data represented in the Parallel Coordinates visualization can be viewed in a data table by ' +
         'clicking on the Data Table tab at the top of the view.',
rfHelpString = 'The Random Forest Panel provides a way to explore the multivariate data analysis performed using the ' +
        'random forest algorithm on the TCGA data.  The tools panel allows for data filtering, selection, and ' +
        'exporting of the circular plot image.  The main view panel has three different data viewing visualizations ' +
        'that have various interactions depending on what action a user takes on the visualization.  See the help ' +
        'sections of each specific view panel for more details on the visualization and user interactions available.',
viewHelpString = 'Two tabs are available to look at the results of Random Forest analysis.  The Graphical tab provides ' +
        'the Genome-level View and the Chromosome-level View.  The Genome-level view displays a circular plot of the multivariate features found in the TCGA dataset.  ' +
        'By scrolling down, or minimizing the Genome-level View the Chromosome-level View is displayed showing the ' +
        'feature associations at a single chromosome level.  <br/>The \'Data Table\' tab can be selected as well.'
        'The Data-level View is shown and provides a way to view a specific feature and its associated links.',
genomeLevelHelpString = 'The Genome-level View is an interactive circular plot showing the links between target and ' +
        'predictor features within the dataset.  Tooltips over various points give the underlying data associated with ' +
        'a node or link.  Clicking on the links within the plot will display a coorelation scatterplot of the associated ' +
        'features.  Mouse clicks on chromosomes, links, and nodes within the plot also bring up drill-down information ' +
        'in the Chromosome-level and Data-level views.<p>' +
'The subset of data shown in the circular plot can be filtered by using the tools panel filtering section.  Once a plot ' +
        'of interest has been found, an export of the plot can be achieved by using the tools panel export option.  ' +
        'The mouse-click behavior of the interactive plot can be changed by choosing different options in the tools ' +
        'panel selection area.',
chromosomeLevelHelpString = 'The Chromosome-level View provides a way to navigate the features of a given dataset on ' +
        'a single chromosome level.  The view will be populated with chromosome information once a chromosome is ' +
        'selected by either clicking on a specific chromosome number  or end-point of a link in the Genome-level view.<p>'+
        'Feature information on a given chromosome is displayed in 4 different plots.  The Distal Intra-Chromosome ' +
        'Correlates plot shows the location of the predictors for a target within a chromosome.  The Proximal Feature ' +
        'Predictors plot also displays feature associations within the chromosome, but only displays ones where the ' +
        'start and end location of a predictor is less than 250,000 bp in length.  The Unmapped Feature Coorelates ' +
        'shows features for which there does not exist a mapped location.  Finally, the Feature Locations plot shows ' +
        'the locations of the various targets involved in the links.   All plots have tooltips giving more details of ' +
        'the underlying data. Coorelation scatterplots are displayed when an item is selected within a plot.<p>' +
'A sliding scale showing all feature locations is given at the bottom of the view.  A range can be selected to zoom ' +
        'in on a given chromosome location by clicking the mouse and dragging it over a region.  The same zoom and ' +
        'selection capability is also available within the top 4 plots.',
dataLevelViewHelpString = 'The Data-level View is a data table displaying the feature selected in the Genome-level ' +
        'view and its related links.  This view allows the user to easily navigate all the related data values ' +
        'associated with a single feature.',
toolsHelpString = 'The Tool Panel provides a way for filtering, selecting, and exporting different datasets.  ' +
        'The Panel can also be minimized by clicking the `>>` icon, which then expands main panel view.  ' +
        'See each individual tool help for further details on their capabilities.',
filteringHelpString = 'The Filtering Panel allows the user to filter the dataset based on target, ' +
        'predictor, and link attributes of the feature associations.',
selectionHelpString = 'The Selection Panel provides a way to customize the selection behavior within the Genome-level ' +
        'view circular plot.',
dataHelpString = 'The Data Panel displays all available datasets that can be selected, filtered, and ' +
        'viewed within the Random Forest View.',
exportHelpString = 'The Export Panel allows the user to export the Genome-level view circular plot into a .svg image.<p>' +
        'How to obtain the image:<br> ' +
        '    1. Click the "Export Plot" button when you have a circular plot that you wish to save.  The textarea below the button will fill with SVG markup.<br/>' +
        '    2. Copy and paste (or Select All + drag and drop) the entire text string in the textarea to a text editor(Notepad, etc).<br/>' +
        '    3. Save the text file to your desktop with a ".svg" extension (ex test.svg).<br/>' +
        '    4. Open the file in a SVG Image manipulator. <a href="http://www.gimp.org/">GIMP</a> is an ' +
        'excellent choice. So is <a href="http://inkscape.org/">Inkscape</a>.<br/>' +
        '    5. Save the image to any format you prefer at any resolution.  You may wish to add a flat background color.<br/>' +
        '    6. You\'re ready to use the image.',
parCoordHelpString = 'The parallel coordinates plot below shows the three different cancer types with their associated ' +
        'structural variation counts for each gene.  A range of items can be selected by clicking and dragging the ' +
        'mouse on any given column.  In this way, genes that ' +
        'display a trend across cancer types can be selected and further explored.';
